//
//  WDMyNotifyCell.m
//  Zhihuijinfu
//
//  Created by 王笛 on 2016/12/7.
//  Copyright © 2016年 王笛. All rights reserved.
//

#import "WDMyNotifyCell.h"
#import "WDMyNotify.h"

@interface WDMyNotifyCell ()
/** 通知小红点 */
@property (weak, nonatomic) IBOutlet UIImageView *notifyView;
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *descriptionLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
/** 查看详情 */
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;
/** 详情图片 */
@property (weak, nonatomic) IBOutlet UIImageView *detailView;
@property (weak, nonatomic) IBOutlet UIView *bottomLine;

@end
@implementation WDMyNotifyCell

+ (instancetype)myNotifyCellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"myNotifyCell";
    WDMyNotifyCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
    }
    
    return cell;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    [self layoutIfNeeded];
    
    self.detailLabel.lineBreakMode = NSLineBreakByCharWrapping;
    
    //要设置label的最大宽度才能正确的显示
    self.detailLabel.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - self.descriptionLabel.frame.origin.x - 20;
}

- (void)setMyNotify:(WDMyNotify *)myNotify
{
    _myNotify = myNotify;
    
    if ([myNotify.status boolValue]) {
        
        self.notifyView.hidden = YES;
        
        self.titleLabel.textColor = ColorForRGB(0xa0a0a0);
        
        self.descriptionLabel.textColor = ColorForRGB(0xa0a0a0);
        
        self.timeLabel.textColor = ColorForRGB(0xa0a0a0);
        
        self.detailLabel.textColor = ColorForRGB(0xa0a0a0);
        
        self.detailView.image = [UIImage imageNamed:@"show_detail_press"];
    }
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:myNotify.image_url] placeholderImage:[UIImage imageNamed:@"defaultIcon"]];
    
    self.titleLabel.text = myNotify.title;
    
    self.descriptionLabel.text = myNotify.descr;
    
    self.timeLabel.text = myNotify.create_time;
    
    CGSize descSize = [self sizeWithString:myNotify.descr font:[UIFont systemFontOfSize:WDScale(14.0)] constraintSize:CGSizeMake(self.detailLabel.preferredMaxLayoutWidth, MAXFLOAT)];
    
    [self.descriptionLabel makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(descSize.height);
    }];
    
    
    [self layoutIfNeeded];
    
    myNotify.myNotifyCellH = CGRectGetMaxY(self.timeLabel.frame) + 15;
}

@end
